#pragma once

#include <vector>
#include <thread>
#include <memory>
#include <atomic>



namespace EZTcp{

class EZLoop;

class EZLoopThreadPool
{
public:
	EZLoopThreadPool(int thread_num = 1);
	~EZLoopThreadPool();

	bool start();

	void stop();

    // @brief Reinitialize some data fields after a fork
    void after_fork();

	EZLoop* next_loop();
private:
	enum Status {
		kNull = 0,
		kRunning = 1,
		kStopping = 2,
		kStopped = 3,
	};
	std::atomic<Status>						status_;		// true runing
	int										thread_num_;
	std::atomic<int>						thread_run_num_;
	std::atomic<int>						thread_stop_num_;
	int										next_loop_id_;
	std::vector<EZLoop*>					loops_;
	std::vector<std::thread>				threads_;
};

}